#pragma once


#ifdef EPOLL
#include <sys/epoll.h>
#else
enum
{
	EPOLLIN = 1,
	EPOLLOUT = 2,
	EPOLLPRI = 4,
	EPOLLERR = 8,
	EPOLLHUP = 0x10,
	EPOLLET = 0x20,
	EPOLLONESHOT = 0x40,
};

enum
{
	EPOLL_CTL_ADD = 1,
	EPOLL_CTL_MOD = 2,
	EPOLL_CTL_DEL = 4,
};

typedef void epoll_event;
#endif

class Cepoll
{
public:
	Cepoll():m_fd(-1)
	{
	}

	~Cepoll()
	{
#ifdef EPOLL
		if (m_fd != -1)
			close(m_fd);
#endif
	}

	int create(int size)
	{
#ifdef EPOLL
		return m_fd = epoll_create(size);
#else
		return 0;
#endif
	}

	int ctl(int op, int fd, int events, void* p)
	{
#ifdef EPOLL
		epoll_event e;
		e.data.ptr = p;
		e.events = events;
		return epoll_ctl(m_fd, op, fd, &e);
#else
		return 0;
#endif
	}

	int wait(epoll_event* events, int maxevents, int timeout)
	{
#ifdef EPOLL
		return epoll_wait(m_fd, events, maxevents, timeout);
#else
		return 0;
#endif
	}


private:
	int m_fd;
};
